#pragma once
#include<string>
#include<string.h>
#include<algorithm>
namespace Log {
	class Buffer {
	private:
		char* buf;
		int maxSize;
		int curSize = 0;
	public:
		Buffer(int maxSize) :maxSize(maxSize) {
			buf = new char[maxSize];
		}
		~Buffer() {
			delete[] buf;
		}
		bool full() {
			return curSize == maxSize;
		}
		bool empty() {
			return curSize == 0;
		}

		int append(const char* msg, int len) {
			len = std::min(len, maxSize - curSize);
			memcpy(buf + curSize, msg, len);
			curSize += len;
			return len;
		}

		const char* data()const { return buf; }
		int size()const { return curSize; }
		void clear() { curSize = 0; }
	};
}
